package org.jfbmonitor.view.attachment;

import java.awt.FontMetrics;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;

import org.jfbmonitor.language.Language;

public class AttachmentColumnModel extends DefaultTableColumnModel {
	private static final long serialVersionUID = 1L;

	public AttachmentColumnModel(FontMetrics fm) {
		int number = fm.stringWidth("0");
		int character = fm.stringWidth("M");
		
		addColumn(createColumn(0, 12 * number, fm, Language.getInstance()
				.getProperties("TABLE.ATTACHMENTID")));
		addColumn(createColumn(1, 7 * character, fm, Language.getInstance()
				.getProperties("TABLE.SERVERPID")));
		addColumn(createColumn(2, 6 * character, fm, Language.getInstance()
				.getProperties("TABLE.STATE")));
		addColumn(createColumn(3, 253 * character, fm, Language.getInstance()
				.getProperties("TABLE.ATTACHMENTNAME")));
		addColumn(createColumn(4, 10 * character, fm, Language.getInstance()
				.getProperties("TABLE.USER")));
		addColumn(createColumn(5, 10 * character, fm, Language.getInstance()
				.getProperties("TABLE.ROLE")));
		addColumn(createColumn(6, 11 * character, fm, Language.getInstance()
				.getProperties("TABLE.REMOTEPROTOCOL")));
		addColumn(createColumn(7, 253 * character, fm, Language.getInstance()
				.getProperties("TABLE.REMOTEADDRESS")));
		addColumn(createColumn(8, 10 * number, fm, Language.getInstance()
				.getProperties("TABLE.REMOTEPID")));
		addColumn(createColumn(9, 253 * character, fm, Language.getInstance()
				.getProperties("TABLE.REMOTEPROCESS")));
		addColumn(createColumn(10, 10 * character, fm, Language.getInstance()
				.getProperties("TABLE.CHARACTERSET")));
		addColumn(createColumn(11, 19 * character, fm, Language.getInstance()
				.getProperties("TABLE.TIMESTAMP")));
		addColumn(createColumn(12, 6 * number, fm, Language.getInstance()
				.getProperties("TABLE.GARBAGECOLLECTION")));
		addColumn(createColumn(13, 6 * number, fm, Language.getInstance()
				.getProperties("TABLE.STATID")));
	}

	private TableColumn createColumn(int columnIndex, int width,
		FontMetrics fm, String title) {
		TableColumn col = new TableColumn(columnIndex);
		col.setCellRenderer(new AttachmentCellRenderer());
		col.setHeaderRenderer(null);
		col.setHeaderValue(title);
		col.setResizable(true);
		col.setMinWidth(0);
		col.setMaxWidth(width);
		return col;
	}

}
